package com.smartwheel.db.mongo;

import java.util.HashMap;
import java.util.Map;
import com.mongodb.DBCollection;
import com.smartwheel.db.DbManager;

public class MongoDbManager implements DbManager{
	
	private DbConnection dbCon;
	private DriveDao dao;
	
	@Override
	public void storeList(String info) {
		DBCollection col = DbConnection.getCollection(DbDef.DRIVE_COL);
		dao.storeList(col, info);
	}

	@Override
	public void storeObject(String info) {
		DBCollection col = DbConnection.getCollection(DbDef.DRIVE_COL);
		dao.storeObject(col, info);
	}

	@Override
	public String get(String userId) {
		DBCollection col = DbConnection.getCollection(DbDef.DRIVE_COL);
		Map<String, String> filters = new HashMap<>();
		filters.put(DbDef.USER_ID_COL_NAME, userId);
		if (dbCon==null) {
			return "";
		}else {
			return dao.find(col, filters);
		}	
	}
	
	public String get(long startTimestamp, long endTimestamp) {
		DBCollection col = DbConnection.getCollection(DbDef.DRIVE_COL);
		return dao.find(col, startTimestamp, endTimestamp);
	}

	@Override
	public String get(Map<String, String[]> criterias) {
		Map<String, String>  filters = new HashMap<>();
		for (String key: criterias.keySet()) {
			filters.put(key, criterias.get(key)[0]);		
		}
		DBCollection col = DbConnection.getCollection(DbDef.DRIVE_COL);
		return dao.find(col, filters);
	}

	public DbConnection getDbCon() {
		return dbCon;
	}

	public void setDbCon(DbConnection dbCon) {
		this.dbCon = dbCon;
	}

	public DriveDao getDao() {
		return dao;
	}

	public void setDao(DriveDao dao) {
		this.dao = dao;
	}
}
